<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="活动" prop="activityName">
        <el-input
          v-model="queryParams.activityName"
          placeholder="请输入活动名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />

<!--        <el-select-->
<!--          v-model="queryParams.activityId"-->
<!--          placeholder="请选择活动"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery">-->
<!--            <el-option v-for="(item,index) in activityList" :label="item.name" :value="item.id" :key="index">-->
<!--            </el-option>-->
<!--        </el-select>-->
      </el-form-item>
      <el-form-item label="活动档期" prop="generationId">
        <el-cascader
          v-model="generationId"
          :options="generations"
          placeholder="请选择活动档期"
          :props="prop"
          @change="handleChange"
          :clearable="true"></el-cascader>
      </el-form-item>
      <el-form-item label="用户姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入用户姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="status" placeholder="请选择" clearable size="small" multiple>
          <el-option  v-for="dict in statusOptions"
                      :key="dict.dictValue"
                      :label="dict.dictLabel"
                      :value="dict.dictValue" />
        </el-select>
      </el-form-item>
      <el-form-item label="支付方式" prop="payWay">
        <el-select v-model="queryParams.payWay" placeholder="请选择支付方式" clearable size="small">
          <el-option label="微信支付" value="1"  />
          <el-option label="会员支付" value="2"  />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['ypp:enroll:exportSiteEnroll']"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5" style="display: flex;flex-direction: column" v-hasPermi="['ypp:enroll:remove']">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          @click="handleDelete"
          :disabled="multiple"

        >删除</el-button>
       <div style="font-size: 12px;color: #BCBCBC;padding-top: 5px;">只支持删除未支付订单</div>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="warning"-->
<!--          :disabled="multiple"-->
<!--          icon="el-icon-success"-->
<!--          size="mini"-->
<!--          @click="handleCheck"-->
<!--          v-hasPermi="['ypp:enroll:checkapplybatch']"-->
<!--        >报名通过</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="danger"-->
<!--          :disabled="multiple"-->
<!--          icon="el-icon-success"-->
<!--          size="mini"-->
<!--          @click="handleCheckOut"-->
<!--          v-hasPermi="['ypp:enroll:checkapply']"-->
<!--        >报名不通过</el-button>-->
<!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="warning"
          :disabled="multiple"
          icon="el-icon-success"
          size="mini"
          @click="handleCheck2"
          v-hasPermi="['ypp:enroll:checkOutBatch']"
        >退出通过</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          :disabled="multiple"
          icon="el-icon-success"
          size="mini"
          @click="handleCheckOut2"
          v-hasPermi="['ypp:enroll:checkOutBatch']"
        >退出不通过</el-button>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="warning"-->
<!--          :disabled="multiple"-->
<!--          icon="el-icon-success"-->
<!--          size="mini"-->
<!--          @click="handleAuditBack"-->
<!--          v-hasPermi="['ypp:enroll:rollBackAudit']"-->
<!--        >退回待审核</el-button>-->
<!--      </el-col>-->

    </el-row>

    <el-table v-loading="loading" :data="enrollList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="订单编号" align="center" prop="id" />
      <el-table-column label="活动名称" align="center" prop="activityName" width="150px">
<!--        <template slot-scope="scope">-->
<!--          <el-button type="text" style="white-space: pre-wrap">{{scope.row.activityName}}</el-button>-->
<!--&lt;!&ndash;          <el-button type="text" @click="openActivity(scope.row.activityId)">{{scope.row.activityName}}</el-button>&ndash;&gt;-->
<!--        </template>-->
      </el-table-column>
      <el-table-column label="档期" align="center" prop="generationName" />
      <el-table-column label="姓名" align="center" prop="name" />
      <el-table-column  label="性别" align="center" prop="gender">
        <template slot-scope="scope">
          <span v-if="scope.row.gender == 1">男</span>
          <span v-else-if="scope.row.gender == 2">女</span>
          <span v-else>未知</span>
        </template>
      </el-table-column>
      <el-table-column label="年龄" align="center" prop="birthday" >
        <template slot-scope="scope" v-if="scope.row.birthday">
          <span>{{ getAge(scope.row.birthday) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="监护人电话" align="center" prop="phone" :show-overflow-tooltip="true"/>
      <el-table-column label="报名时间" align="center" prop ="createTime" :show-overflow-tooltip="true"/>
      <el-table-column label="付款方式" align="center" prop="payWay">
        <template slot-scope="scope">
          <span v-if="scope.row.detailId && scope.row.payNo">权益+微信支付</span>
          <span v-else-if="scope.row.detailId||(scope.row.couponId&&!scope.row.payNo)">权益支付</span>
          <span v-else-if="scope.row.payNo">微信支付</span>
          <span v-else>免费</span>
        </template>
      </el-table-column>
      <el-table-column  label="状态" align="center" prop="status"  >
        <template slot-scope="scope">
          <span :class="'status_'+scope.row.status">{{ statusFormat(scope.row) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="实付金额" align="center" prop="enrollCost" />
      <el-table-column label="付款单号" align="center" prop="payNo" :show-overflow-tooltip="true"/>
<!--      <el-table-column label="付款时间" align="center" prop="payTime" :show-overflow-tooltip="true"/>-->
<!--      <el-table-column label="备注" align="center" prop="remark" />-->
      <el-table-column label="权益消耗" align="center" prop="qy">
        <template slot-scope="scope">
          <span >{{ scope.row.detailId  ? scope.row.rightCount+"次":'0次' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-error"-->
<!--            @click="handleCheckOut(scope.row)"-->
<!--            v-hasPermi="['ypp:enroll:checkapply']"-->
<!--            v-if="scope.row.status==0"-->
<!--          >审核不通过</el-button>-->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-error"
            @click="handleCheckOut2(scope.row)"
            v-hasPermi="['ypp:enroll:checkout']"
            v-if="scope.row.status==4"
          >退出不通过</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-error"
            style="color: #ff3f3f"
            @click="handleCheckQuery(scope.row)"
            v-hasPermi="['ypp:enroll:checkout']"
            v-if="scope.row.status == 3 || scope.row.status == 6"
          >未通过原因</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-info"
            @click="handleQueryItem(scope.row)"
            v-hasPermi="['ypp:enroll:query']"
          >详情</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            v-if="scope.row.status == 7"
            @click="handleEditPrice(scope.row)"
            v-hasPermi="['ypp:enroll:edit']"
          >改价格</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            v-if="scope.row.status != 3&&scope.row.status != 5&&scope.row.status != 7&&scope.row.status != 11&&scope.row.enrollCost&&scope.row.enrollCost>0"
            @click="handleRefund(scope.row)"
            v-hasPermi="['ypp:enroll:edit']"
          >部分退款</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleChangeGeneration(scope.row)"
            v-hasPermi="['ypp:enroll:changeGeneration']"
          >修改档期</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 报名人对话框 -->
    <el-dialog  width="500px"  title="会员信息" :visible.sync="dialogFormVisible" @close="close">
      <el-descriptions border column="2">
        <el-descriptions-item  label="姓名">
          {{user.realName}}
        </el-descriptions-item>
        <el-descriptions-item  label="年龄" v-if="user.birthday">
          <template slot-scope="scope">
            <span>{{ getAge(user.birthday) }}</span>
          </template>
        </el-descriptions-item>
        <el-descriptions-item label="性别">
          <span v-if="user.gender==1">男</span><span v-if="user.gender==2">女</span>
        </el-descriptions-item>
        <el-descriptions-item  label="电话">
          {{user.phone}}
        </el-descriptions-item>
      </el-descriptions>
    </el-dialog>
    <!-- 报名活动框 -->
    <el-dialog  width="500px" title="活动信息" :visible.sync="dialogActivityFormVisible" @close="close">
      <el-descriptions border column="1">
        <el-descriptions-item  label="活动名称">
          {{activity.name}}
        </el-descriptions-item>
        <el-descriptions-item  label="活动时间">
          {{activity.startTime}} - {{activity.activityEndTime}}
        </el-descriptions-item>
      </el-descriptions>
    </el-dialog>

    <!-- 审核不通过，审核意见 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px" >

        <el-form-item label="报名审核意见" prop="outCause" v-if="check==1">
          <el-input
            type="textarea"
            :rows="4"
            placeholder="报名审核意见"
            v-model="form.outCause">
          </el-input>
        </el-form-item>

        <el-form-item label="取消活动审核意见" prop="outCause" v-if="check==2">
          <el-input
            type="textarea"
            :rows="4"
            placeholder="取消活动审核意见"
            v-model="form.outCause">
          </el-input>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" :loading="readLoad">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog :title="title" :visible.sync="visible1" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px" >
        <el-form-item label="原因" prop="applyAudit">
          <el-input
            type="textarea"
            :rows="4"
            placeholder="审核意见"
            v-model="form.outCause"
            readonly>
          </el-input>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="visible1 = false">关 闭</el-button>
      </div>
    </el-dialog>

    <el-dialog title="活动报名详情" :visible.sync="detailOpen" width="500px" append-to-body>
     <el-descriptions title="活动信息" :column="1">
       <el-descriptions-item label="活动图片">
         <el-image style="width: 300px;height: 300px;" fit="contain" :src="imageUrl+enrollDetail.cover" :preview-src-list="[imageUrl+enrollDetail.cover]"></el-image>
       </el-descriptions-item>
       <el-descriptions-item label="活动名称">
         {{enrollDetail.activityName}}
       </el-descriptions-item>
       <el-descriptions-item label="活动时间">
         {{enrollDetail.startTime}}-{{enrollDetail.endTime}}
       </el-descriptions-item>
       <el-descriptions-item label="报名时间">
         {{enrollDetail.createTime}}
       </el-descriptions-item>
     </el-descriptions>
      <el-descriptions title="营员信息" :column="2">
        <el-descriptions-item label="姓名">
           {{enrollDetail.name}}
        </el-descriptions-item>
        <el-descriptions-item label="性别">
          {{genderFormat(enrollDetail.gender)}}
        </el-descriptions-item>
        <el-descriptions-item label="性格特点" v-if="enrollDetail.personality">
          {{enrollDetail.personality}}
        </el-descriptions-item>
        <el-descriptions-item label="年龄" v-if="enrollDetail.birthday">
          {{getAge(enrollDetail.birthday)}}
        </el-descriptions-item>
        <el-descriptions-item label="身高" v-if="enrollDetail.height">
          {{enrollDetail.height}}
        </el-descriptions-item>
        <el-descriptions-item label="体重" v-if="enrollDetail.weight">
          {{enrollDetail.weight}}
        </el-descriptions-item>
        <el-descriptions-item label="证件类型">
          {{cardFormat(enrollDetail.idType)}}
        </el-descriptions-item>
        <el-descriptions-item label="证件号">
          {{enrollDetail.identityNumber}}
        </el-descriptions-item>
        <el-descriptions-item label="学校">
          {{enrollDetail.school}}
        </el-descriptions-item>
        <el-descriptions-item label="班级">
          {{enrollDetail.grade}}
        </el-descriptions-item>
        <el-descriptions-item label="监护人电话">
          {{enrollDetail.phone}}
        </el-descriptions-item>
        <el-descriptions-item label="紧急联系电话">
          {{enrollDetail.emergencyPhone}}
        </el-descriptions-item>
        <el-descriptions-item label="地区">
          {{enrollDetail.region}}
        </el-descriptions-item>
      </el-descriptions>
      <el-descriptions title="特殊情况" :column="1" :labelStyle="{display:'none'}">
        <el-descriptions-item>
          {{enrollDetail.remark?enrollDetail.remark:'暂无'}}
        </el-descriptions-item>
      </el-descriptions>
      <el-descriptions :title="'家长'+(index+1)+'信息'" v-for="(item,index) in enrollDetail.parent" :key="index" :column="2" v-if="enrollDetail.parent&&enrollDetail.parent.length>0">
          <el-descriptions-item label="姓名">
            {{item.name}}
          </el-descriptions-item>
          <el-descriptions-item label="证件类型">
            {{cardFormat(item.idType)}}
          </el-descriptions-item>
          <el-descriptions-item label="证件号">
            {{item.identityNumber}}
          </el-descriptions-item>

      </el-descriptions>
      <el-descriptions title="订单信息" :column="2">
        <el-descriptions-item label="订单编号" v-if="enrollDetail.payWay==1&&enrollDetail.payNo">
          {{enrollDetail.payNo}}
        </el-descriptions-item>
        <el-descriptions-item label="缴费方式">
          <template>
            <span v-if="enrollDetail.detailId && enrollDetail.payNo">权益+微信支付</span>
            <span v-else-if="enrollDetail.detailId||(enrollDetail.couponId&&!enrollDetail.payNo)">权益支付</span>
            <span v-else-if="enrollDetail.payNo">微信支付</span>
            <span v-else>免费</span>
          </template>
        </el-descriptions-item>
        <el-descriptions-item label="缴费金额" v-if="enrollDetail.enrollCost">
          {{enrollDetail.enrollCost}}
        </el-descriptions-item>
        <el-descriptions-item label="优惠券抵扣" v-if="enrollDetail.couponPrice">
          {{enrollDetail.couponPrice}}
        </el-descriptions-item>
        <el-descriptions-item label="权益消耗" v-if="enrollDetail.detailId">
          {{  enrollDetail.rightCount?enrollDetail.rightCount:1 }}次
        </el-descriptions-item>
        <el-descriptions-item label="状态">
          {{enrollDetail.statusName}}
        </el-descriptions-item>
        <el-descriptions-item label="退款原因" v-if="enrollDetail.refundReason">
          {{enrollDetail.refundReason}}
        </el-descriptions-item>
        <el-descriptions-item label="退款操作人" v-if="enrollDetail.refundBy">
          {{enrollDetail.refundBy}}
        </el-descriptions-item>
      </el-descriptions>
      <el-descriptions title="取消信息" :column="2"  v-if="enrollDetail.status==5">
        <el-descriptions-item label="取消报名时间">
         {{enrollDetail.cancelTime}}
        </el-descriptions-item>
        <el-descriptions-item label="退款金额" v-if="enrollDetail.refundPrice">
          {{enrollDetail.refundPrice}}
        </el-descriptions-item>
        <el-descriptions-item label="扣费金额" v-if="enrollDetail.enrollCost&&enrollDetail.refundPrice">
          {{enrollDetail.enrollCost - enrollDetail.refundPrice}}
        </el-descriptions-item>
        <el-descriptions-item label="退回权益"  v-if="enrollDetail.detailId">
          1次
        </el-descriptions-item>
        <el-descriptions-item label="状态">
          {{enrollDetail.statusName}}
        </el-descriptions-item>
      </el-descriptions>
    </el-dialog>
    <el-dialog title="档期修改" :visible.sync="generationOpen" width="500px" append-to-body>
      <el-form>
        <el-form-item label="档期" prop="generationId">
          <el-select v-model="enroll.generationId" :value="enroll.generationId" placeholder="请选择档期">
            <el-option v-for="item in generation"
                       :key="item.value"
                       :label="item.label"
                       :value="item.value"/>
          </el-select>
          <el-form-item>
            <el-button type="primary"  size="mini" @click="submitGenerationChange">确认</el-button>
          </el-form-item>
        </el-form-item>
      </el-form>
    </el-dialog>
    <el-dialog title="退款操作" :visible.sync="refundOpen" width="500px" append-to-body>
      <el-form >
        <el-form-item label="退款原因">
          <el-input v-model="refund.reason"/>
        </el-form-item>
        <el-form-item label="退款金额">
          <el-input v-model="refund.money"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="refundConfirm">确 定</el-button>
        <el-button type="primary" @click="refundOpen = false">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import{ getUser } from '@/api/wx/user';
import { editBy, editPrice,changeGeneration,checkOutBatch2,listSnpEnroll,getSnpEnrollDetail, delSnpEnroll, exportSelectedSnpEnroll,exportSnpEnroll,snpCheckApply, snpCheckApplyBatch, checkOut, snpCheckOutBatch, snpRollBackAudit } from "@/api/ypp/enroll";
import {getActivity, listActivity} from "@/api/ypp/activity";
import {listGeneration} from "../../../api/ypp/generation";

export default {
  name: "Enroll",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 活动报名表格数据
      enrollList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否显示弹出层
      visible1: false,
      //判断报名或退赛、1报名、2退赛
      check:0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        activityId: undefined,
        wxUserId: undefined,
        name: undefined,
        corpName: undefined,
        payWay: undefined,
        remark:undefined,
        status: undefined,
        activityName:undefined,
        wxClientId:10
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      activityList:[],
      generations:[],
      statusOptions:[],
      user:{},
      dialogFormVisible:false,
      readLoad:false,
      dialogActivityFormVisible:false,
      activity:{},
      enrollDetail:{},
      detailOpen:false,
      imageUrl:process.env.VUE_APP_BASE_API,
      cardOptions:[],
      status:[],
      prop:{ expandTrigger: 'hover' },
      generationId:[],
      generationOpen:false,
      enroll:{},
      generation:[],
      refundOpen:false,
      refund:{
        reason:'',
        money:0,
        id:0
      }
    };
  },
  created() {
    this.getActivityList();
    this.getList();
    this.getDicts("card_type").then(response => {
      this.cardOptions = response.data;
    });

  },
  methods: {
    /*根据出生日期算出年龄*/
    getAge(strBirthday){
      var returnAge;
      var strBirthdayArr=strBirthday.split("-");
      var birthYear = strBirthdayArr[0];
      var birthMonth = strBirthdayArr[1];
      var birthDay = strBirthdayArr[2];
      var d = new Date();
      var nowYear = d.getFullYear();
      var nowMonth = d.getMonth() + 1;
      var nowDay = d.getDate();
      if(nowYear == birthYear){
        returnAge = 0;//同年 则为0岁
      }
      else{
        var ageDiff = nowYear - birthYear ; //年之差
        if(ageDiff > 0){
          if(nowMonth == birthMonth) {
            var dayDiff = nowDay - birthDay;//日之差
            if(dayDiff < 0)
            {
              returnAge = ageDiff - 1;
            }
            else
            {
              returnAge = ageDiff ;
            }
          }
          else
          {
            var monthDiff = nowMonth - birthMonth;//月之差
            if(monthDiff < 0)
            {
              returnAge = ageDiff - 1;
            }
            else
            {
              returnAge = ageDiff ;
            }
          }
        }
        else
        {
          returnAge = -1;//返回-1 表示出生日期输入错误 晚于今天
        }
      }
      return returnAge;//返回周岁年龄
},
    // 状态字典翻译
    cardFormat(type) {
      return this.selectDictLabel(this.cardOptions, type);
    },
    openActivity(id){
      getActivity(id).then(response => {
        this.activity = response.data;
        this.dialogActivityFormVisible=true;
      });
    },
    openUser(id){
      getUser(id).then(response => {
        this.user = response.data;
        this.dialogFormVisible=true;
      });
    },
    // 状态类型字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },
    genderFormat(gender){
      if(gender == "1"){
        return "男"
      }else if(gender == "2"){
        return "女"
      }else{
        return "未知"
      }
    },
    /** 查询活动报名列表 */
    getList() {
      this.loading = true;
      listSnpEnroll(this.queryParams).then(response => {
        this.enrollList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getActivityList(){
      var that = this;
      this.getDicts("ypp_activity_enroll_status").then(response => {
        this.statusOptions = response.data;
      });
      listActivity().then(response => {
        that.activityList = response.rows;
      });
      listGeneration().then(res=>{
       if(res.code === 200){
         var generations = res.rows;
         var map = new Map();
         generations.map(function(item,index){
           if(index!==0){
             if(map.has(item.activityId)){
               map.get(item.activityId).children.push({label:item.name,value:item.id})
             }else{
               map.set(item.activityId,{label:item.activityName,value:item.activityId,children:[{label:item.name,value:item.id}]});
             }
           }else{
             map.set(item.activityId,{label:item.activityName,value:item.activityId,children:[{label:item.name,value:item.id}]});
           }
         });
         console.log(map);
         let list = [];
         for(let [key,val] of map.entries()){
           list.push(val)
         }
         that.generations =  list;
       }
      })
    },
    mapToArray(map) {
      var list = [];
      for (var key in map) {
        list.push(map[key]);
      }
      return list;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
      this.check = 0;
    },
    // 表单重置
    reset() {
      this.check = 0;
      this.form = {
        id: undefined,
        activityId: undefined,
        wxUserId: undefined,
        name: undefined,
        corpName: undefined,
        payWay: undefined,
        status: "0",
        delFlag: undefined,
        enrollCost: undefined,
        remark: undefined,
        outCause: undefined,
        createTime: undefined,
        updateTime: undefined,
        type: undefined,
        membership: undefined
      };
      this.resetForm("form");
    },
    handleChange(e){
      this.queryParams.generationId = e[1];
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      if(this.status&&this.status.length>1){
        this.queryParams.remark = this.status.join(",");
        this.queryParams.status = undefined;
      }else if(this.status&&this.status.length===1){
        this.queryParams.remark = undefined;
        this.queryParams.status = this.status[0];
      }else{
        this.queryParams.remark = undefined;
        this.queryParams.status = undefined;
      }
      this.getList();
    },
    //查看详情
    handleQueryItem(row){
      this.reset();
      const id = row.id || this.ids
      getSnpEnrollDetail(id).then(res=>{
        if(res.code == 200){
          this.detailOpen = true;
          this.enrollDetail = res.data
        }
      })
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加活动报名";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getSnpEnrollDetail(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改活动报名";
      });
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != undefined) {
            if(this.check==1){

              let query = ""
            if(!this.form.outCause){
                this.msgError("请输入失败原因")
                return
              }
              if (this.ids.length > 0) {
                for (let i = 0; i < this.ids.length;i++) {
                  this.ids[i] = "ids=" + this.ids[i]
                }
                query = this.ids.join("&")
              } else {
                query = "ids=" + this.form.id;
              }
              if (this.form.outCause != undefined && this.form.outCause != "") {
                query = query + "&outCause=" + this.form.outCause;
              }
              this.syncData(query);
            }

            if(this.check==2){
            var id =  this.form.id || this.ids
              if (!this.form.outCause) {
                this.msgError("请输入失败原因")
                return
              }
              checkOutBatch2(id,this.form.outCause).then(response => {
                if (response.code === 200) {
                  this.msgSuccess("操作成功");
                  this.open = false;
                  this.getList();
                }
              });
            }

          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      console.log(ids)
      this.$confirm('是否确认删除活动报名编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delSnpEnroll(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport(row) {
      const ids = row.id || this.ids;
      if(ids&&ids.length>0){
        this.$confirm('是否确认导出选中的活动报名数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportSelectedSnpEnroll(ids);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
      }else{
        const queryParams = this.queryParams;
        this.$confirm('是否确认导出所有活动报名数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportSnpEnroll(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
      }

    },
    /** 报名审核不通过 */
    handleCheckOut(row) {
      this.reset();
      let id = row.id || this.ids

      this.check=1;
      this.form.id = id;
      this.open = true;
      this.title = "审核意见";
    },
    // 报名成功退回待审核状态
    handleAuditBack(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认退回待审核状态，报名信息编号为"' + ids + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return snpRollBackAudit(ids);
      }).then(() => {
        this.getList();
        this.msgSuccess("退回成功");
      }).catch(function() {});
    },

    /** 退赛审核不通过 */
    handleCheckOut2(row) {
      this.reset();
      const id = row.id || this.ids
      this.check=2;
      this.form.id = id;
      this.open = true;
      this.title = "审核意见";
      // this.check=0;
    },
    // 查看审核不通过原因
    handleCheckQuery(row) {
      this.reset();
      const id = row.id || this.ids
      getSnpEnrollDetail(id).then(response => {
        this.title = "未通过原因";
        this.form.outCause = response.data.outCause
        this.visible1 = true
      });
    },
    syncData(query){
      var that = this;
      this.readLoad = true;
      snpCheckApply(query).then(response => {
        that.getList();
        that.readLoad = false;
        that.$alert(response.msg, "生成结果", { dangerouslyUseHTMLString: true,type: "success" });
        that.open = false;
      }).catch(function(res) {
        that.getList();
        that.readLoad = false;
        that.open = false;
      });
    },

    /** 报名审核按钮操作 */
    handleCheck(row) {
      const ids = row.id || this.ids;
      console.log(ids)
      if(ids==undefined || ids==null ||ids.length==0){
        this.$message.error('请勾选至少一个待审核报名');
      }else{
        this.$confirm('是否确认审核通过报名信息编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return snpCheckApplyBatch(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("操作成功");
        }).catch(function() {});
      }

    },
    /** 取消审核按钮操作 */
    handleCheck2(row) {
      const ids = row.id || this.ids;
      if(ids==undefined || ids==null ||ids.length==0){
        this.$message.error('请勾选至少一个待取消报名');
      }else{
        this.$confirm('是否确认审核通过报名信息编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return snpCheckOutBatch(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("操作成功");
        }).catch(function() {});
      }

    },
    close(){
        this.dialogFormVisible=false;
    },
    handleEditPrice(row){
      var that = this;
      this.$prompt('请输入要折扣的金额', "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消"
      }).then(({ value }) => {
        editPrice(row.id, value , 0,'').then(response => {
          if (response.code === 200) {
            this.msgSuccess("操作成功");
            setTimeout(function(){
              that.getList()
            },500)
          }
        });
      }).catch(() => {});
    },
    handleRefund(row){
      var that = this;
      this.refund.id = row.id;
     this.refundOpen = true;
    },
    refundConfirm(){
      var that = this;
      editPrice(this.refund.id, this.refund.money , 1,this.refund.reason).then(response => {
        if (response.code === 200) {
          this.msgSuccess("操作成功");
          setTimeout(function(){
            that.refundOpen = false;
            that.getList()
          },500)
        }
      });
    },
    handleChangeGeneration(row){
      var that = this;
      that.enroll.id =  row.id;
      var activityId = row.activityId;
      that.generation = [];
      this.generations.map(function(item){
        if(item.value == activityId){
          that.generation = item.children;
        }
      });
      this.generationOpen = true;

    },
    submitGenerationChange(){
      var that = this;
      this.generationOpen = false;
      changeGeneration(this.enroll.id,this.enroll.generationId).then(response => {
        if (response.code === 200) {
          this.msgSuccess("操作成功");
          this.enroll = {};
          setTimeout(function(){
            that.getList()
          },500)
        }
      });
    }
  }

};
</script>
<style slot-scope="scope">
  .status_0,.status_7,.status_4,.status_6,.status_8{
    color: red;
  }
  .status_1,.status_2,.status_9,.status_10{
    color: blue;
  }
  .status_3,.status_5,.status_11{
    color: grey;
  }
</style>
